﻿using System;
using System.Collections.Generic;
using System.Linq;

using Fuse8.DomainFramework.Common;
using Fuse8.DomainFramework.Common.Locator;
using Fuse8.DomainFramework.BusinessService;

using Fuse8.ContentManagementFramework.Domain;
using Fuse8.ContentManagementFramework.Domain.Commands;
using Fuse8.ContentManagementFramework.Domain.Commands.CommandParameters;

namespace Fuse8.ContentManagementFramework.BizFacade.Services
{
    public class CmsSiteAdminMapService : BaseBusinessService<CmsSiteAdminMap, int>
    {
        public IEnumerable<CmsSiteAdminMap> GetFirstLevelNodes(CmsUser user)
        {
            Guard.ArgumentNotNull(user, "user");

            var result = FindAllForUser(user) ?? new List<CmsSiteAdminMap>();

            return result.Where(p => p.Level == 1 && p.IsVisible);
        }

        public IEnumerable<CmsSiteAdminMap> FindAllForUser(CmsUser user)
        {
            Guard.ArgumentNotNull(user, "user");

            var command = DependencyServiceLocator.Current.GetInstance<CmsSiteAdminMapSelectForUserCommand>();

            var commandParameter = new CmsSiteAdminMapSelectForUserCommandParameter
            {
                UserId = user.Id
            };

            command.ConfigureCommand(commandParameter);

            return Find(command);
        }
    }
}
